package com.ydsungan.serviceimpl;

import com.ydsungan.bean.Student;
import com.ydsungan.dao.SigninDao;
import com.ydsungan.dao.StudentDao;
import com.ydsungan.daoimpl.SigninDaoImpl;
import com.ydsungan.daoimpl.StudentDaoImpl;
import com.ydsungan.service.StudentService;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

public class StudentServiceImpl implements StudentService {

    SqlSessionFactory sqlSessionFactory = null;
    private StudentDao studentDao = null;

    public StudentServiceImpl() throws IOException {
        //获取sqlSessionFactory对象
        SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
        InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");
        sqlSessionFactory = builder.build(inputStream);
        studentDao = new StudentDaoImpl(this.sqlSessionFactory);
    }

    @Override
    public Student findStudentByMap(Map<String, Object> map) {
        return studentDao.findStudentByMap(map);
    }

    @Override
    public List<Student> findAllStudent() {
        return studentDao.findAllStudent();
    }
}
